package com.yunfei.api.v1.param.createZuoFeiXieYi;
import com.yunfei.api.v2.enums.CreateZuoFeiXieYiTemplateDataEnum;

import java.util.ArrayList;
import java.util.List;

/**
 * @program: 生成作废协议合同模板关键字替换
 * @author: zhengyunfei
 * @create: 2019-07-29 17:15
 **/
public class ZuoFeiXieYiTemplateReplaceKeyValueList {
  private String key;
  private String value;

    public ZuoFeiXieYiTemplateReplaceKeyValueList(String key, String value) {
        this.key = key;
        this.value = value;
    }

    public String getKey() {
        return key;
    }

    public void setKey(String key) {
        this.key = key;
    }

    public String getValue() {
        return value;
    }

    public void setValue(String value) {
        this.value = value;
    }
    /**
    * @Description: 将json数据替换为模板需要的json数据
    * @Author: zhengyunfei
    * @Date: 2019/8/14
    * @time:11:23
    */
    public static StringBuffer replace(String json){
        List<ZuoFeiXieYiTemplateReplaceKeyValueList> list=new ArrayList<>();
        //如果key有部分重复对的，则先加长度比较长的
        list.add(new ZuoFeiXieYiTemplateReplaceKeyValueList(CreateZuoFeiXieYiTemplateDataEnum.contractNum.getCode(),CreateZuoFeiXieYiTemplateDataEnum.contractNum.getMessage()));
        list.add(new ZuoFeiXieYiTemplateReplaceKeyValueList(CreateZuoFeiXieYiTemplateDataEnum.signDateY.getCode(),CreateZuoFeiXieYiTemplateDataEnum.signDateY.getMessage()));
        list.add(new ZuoFeiXieYiTemplateReplaceKeyValueList(CreateZuoFeiXieYiTemplateDataEnum.signDateM.getCode(),CreateZuoFeiXieYiTemplateDataEnum.signDateM.getMessage()));
        list.add(new ZuoFeiXieYiTemplateReplaceKeyValueList(CreateZuoFeiXieYiTemplateDataEnum.signDateD.getCode(),CreateZuoFeiXieYiTemplateDataEnum.signDateD.getMessage()));
        list.add(new ZuoFeiXieYiTemplateReplaceKeyValueList(CreateZuoFeiXieYiTemplateDataEnum.custNm.getCode(),CreateZuoFeiXieYiTemplateDataEnum.custNm.getMessage()));
        list.add(new ZuoFeiXieYiTemplateReplaceKeyValueList(CreateZuoFeiXieYiTemplateDataEnum.mangerNm.getCode(),CreateZuoFeiXieYiTemplateDataEnum.mangerNm.getMessage()));
        list.add(new ZuoFeiXieYiTemplateReplaceKeyValueList(CreateZuoFeiXieYiTemplateDataEnum.contNm.getCode(),CreateZuoFeiXieYiTemplateDataEnum.contNm.getMessage()));
        list.add(new ZuoFeiXieYiTemplateReplaceKeyValueList(CreateZuoFeiXieYiTemplateDataEnum.canRemark.getCode(),CreateZuoFeiXieYiTemplateDataEnum.canRemark.getMessage()));
        for(int i=0;i<list.size();i++){
            String key=list.get(i).getKey();
            String value=list.get(i).getValue();
            if(json.contains(key)){
                json=json.replace(key,value);
            }
        }
        StringBuffer stringBuffer= new StringBuffer();
        stringBuffer.append(json.replace("",""));
        return stringBuffer;
    }
}
